package com.zhf.springboot.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: 曾鸿发
 * @create: 2022-01-10 23:24
 * @description：
 **/
@Configuration
public class FanoutConfig {

    // 声明队列
    @Bean
    public Queue fanoutQ1(){
        return new Queue("fanout.q1");
    }

    @Bean
    public Queue fanoutQ2(){
        return new Queue("fanout.q2");
    }

    // 声明exchange
    public FanoutExchange setFanoutExchange(){
        return new FanoutExchange("fanoutExchange");
    }

    // 声明Binding, exchange 与 queue 的绑定关系
    public Binding bindQ1(){
        return BindingBuilder.bind(fanoutQ1()).to(setFanoutExchange());
    }

    @Bean
    public Binding bindQ2(){
        return BindingBuilder.bind(fanoutQ2()).to(setFanoutExchange());
    }
}
